﻿// See https://aka.ms/new-console-template for more information
using GenericHostDemo.Interface;
using GenericHostDemo;

Console.WriteLine("Hello, World!");

// 构建并运行主机
var host = new HostBuilder()
    .ConfigureServices(services => {
        services.AddSingleton<IHostedService>(new MyBackgroundService());
    })
    .Build();

await host.StartAsync();  // 输出 "Service started!"
await Task.Delay(1000);   // 模拟运行
await host.StopAsync();   // 输出 "Service stopped!"

class MyBackgroundService : IHostedService
{
    public Task StartAsync()
    {
        Console.WriteLine("Service started!");
        return Task.CompletedTask;
    }



    public Task StopAsync()
    {
        Console.WriteLine("Service stopped!");
        return Task.CompletedTask;
    }
}

